﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;

public partial class Fileupload : System.Web.UI.Page
{
    string UpPath;  
    protected void Page_Load(object sender, EventArgs e)


    {
        LblTime.Text = DateTime.Now.ToString();

                  
       UpPath ="c:\\UploadUserFiles";
       // UpPath = Server.MapPath(  + "\\upload";
       if (! Directory.Exists(UpPath))
       {
           Directory.CreateDirectory(UpPath + "\\");
       }   

	

    }
    
protected void  BtnUploadButton_Click(object sender, EventArgs e)
{
    Filename.InnerHtml = FileUpload1.PostedFile.FileName;
    FileContent.InnerHtml = FileUpload1.PostedFile.ContentType;
    FileSize.InnerHtml = FileUpload1.PostedFile.ContentLength.ToString();
    UploadDetails.Visible = true;

    string myFileName;
    myFileName = FileUpload1.PostedFile.FileName;
    string c = System.IO.Path.GetFileName(myFileName);
    try
    {
        FileUpload1.PostedFile.SaveAs(UpPath+"\\" + c);
        span1.InnerHtml = "File upload successful";

    }
    catch (Exception)
    {
        span1.InnerHtml = "File upload FAILED";
        UploadDetails.Visible = false;
        
    }

 
}
}
